package com.valeandre.euroro;

import java.text.FieldPosition;
import java.text.Format;
import java.text.ParsePosition;
 
@SuppressWarnings("serial")
public class MyFormat extends Format {
 
        @Override
        public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
 
        	Number num = (Number) obj;
            // using num.intValue() will floor the value, so we add 0.5 to round instead:
            int roundNum = (int) (num.floatValue() + 0.5f);
            switch(roundNum) {
                case 0:
                    toAppendTo.append("GOLD");
                    break;
                case 1:
                    toAppendTo.append("SILVER");
                    break;
                case 2:
                    toAppendTo.append("PLATINUM");
                    break;
                case 3:
                    toAppendTo.append("PALLADIUM");
                    break;
                default:
                    toAppendTo.append("Unknown");
            }
            return toAppendTo;
        }
 
        @Override
        public Object parseObject(String source, ParsePosition pos) {
            return null;  // We don't use this so just return null for now.
        }
}